package io.github.soiff.mdoc.holder;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;

/**
 * Created by zhangh on 10/25/2016.
 *
 * @author : zhangh@dtdream.com
 * @version : 1.0.0
 * @since : 1.8
 */
@SuppressWarnings({"unused", "unchecked"})
public class Context extends HashMap<String, Object> {
    private static final long serialVersionUID = 0L;

    public String getTitle() {return (String)super.get(Keys.TITLE.toString());}
    public String getType() {return (String)super.get(Keys.TYPE.toString());}
    public String getMethod() {return (String)super.get(Keys.METHOD.toString());}
    public String getVersion() {return (String)super.get(Keys.VERSION.toString());}
    public String getArtifact() {return (String)super.get(Keys.ARTIFACT.toString());}
    public String getAuthor() {return (String)super.get(Keys.AUTHOR.toString());}
    public Date getDate() {return (Date)super.get(Keys.DATE.toString());}
    public String getRemark() {return (String)super.get(Keys.REMARK.toString());}
    public Annotation getParent() {return (Annotation)super.get(Keys.PARENT.toString());}
    public Annotation getSelf() {return (Annotation)super.get(Keys.SELF.toString());}
    public List<Primitive> getInput() {return (List<Primitive>)super.get(Keys.INPUT.toString());}
    public List<Type> getTypes() {return (List<Type>)super.get(Keys.TYPES.toString());}
    public Primitive getReturn() {return (Primitive)super.get(Keys.RETURN.toString());}
    public String getRequest() {return (String) super.get(Keys.REQUEST.toString());}
    public String getResponse() {return (String) super.get(Keys.RESPONSE.toString());}

    public void setTitle(String title) {super.put(Keys.TITLE.toString(), title);}
    public void setType(String type) {super.put(Keys.TYPE.toString(), type);}
    public void setMethod(String method) {super.put(Keys.METHOD.toString(), method);}
    public void setVersion(String version) {super.put(Keys.VERSION.toString(), version);}
    public void setArtifact(String artifact) {super.put(Keys.ARTIFACT.toString(), artifact);}
    public void setAuthor(String author) {super.put(Keys.AUTHOR.toString(), author);}
    public void setDate(Date date) {super.put(Keys.DATE.toString(), date);}
    public void setRemark(String remark) {super.put(Keys.REMARK.toString(), remark);}
    public void setParent(Annotation parent) {super.put(Keys.PARENT.toString(), parent);}
    public void setSelf(Annotation self) {super.put(Keys.SELF.toString(), self);}
    public void setInput(List<Primitive> input) {super.put(Keys.INPUT.toString(), input);}
    public void setTypes(List<Type> types) {super.put(Keys.TYPES.toString(), types);}
    public void setReturn(Primitive ret) {super.put(Keys.RETURN.toString(), ret);}
    public void setRequest(String request) {super.put(Keys.REQUEST.toString(), request);}
    public void setResponse(String response) {super.put(Keys.RESPONSE.toString(), response);}

    public void addInput(Primitive input) {((List<Primitive>)super.get(Keys.INPUT.toString())).add(input);}
    public void addType(Type type) {((List<Type>)super.get(Keys.TYPES.toString())).add(type);}
    public void addType(String type, List<Primitive> fields) {((List<Type>)super.get(Keys.TYPES.toString())).add(new Type(type, fields));}

    @Override
    public void clear() {
        super.clear();
        prepare();
    }

    private void prepare() {
        super.put(Keys.REMARK.toString(), "");
        super.put(Keys.INPUT.toString(), new ArrayList<Primitive>(32));
        super.put(Keys.TYPES.toString(), new ArrayList<Type>(8));
    }

    public Context(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
        prepare();
    }

    public Context(int initialCapacity) {
        super(initialCapacity);
        prepare();
    }

    public Context() {
        prepare();
    }

    public Context(Map<? extends String, ?> m) {
        super(m);
        prepare();
    }

    @Deprecated
    @Override
    public Object put(String key, Object value) {return null;}
    @Deprecated
    @Override
    public void putAll(Map<? extends String, ?> m) {}
    @Deprecated
    @Override
    public Object remove(Object key) {return null;}
    @Deprecated
    @Override
    public Object putIfAbsent(String key, Object value) {return null;}
    @Deprecated
    @Override
    public boolean remove(Object key, Object value) {return false;}
    @Deprecated
    @Override
    public boolean replace(String key, Object oldValue, Object newValue) {return false;}
    @Deprecated
    @Override
    public Object replace(String key, Object value) {return null;}
    @Deprecated
    @Override
    public Object merge(String key, Object value, BiFunction<? super Object, ? super Object, ?> remappingFunction) {return null;}
    @Deprecated
    @Override
    public void replaceAll(BiFunction<? super String, ? super Object, ?> function) {}
}
